400字文章

您所在的位置:网站首页 mybatisplus pagemaps 400字文章

400字文章

#400字文章| 来源: 网络整理| 查看: 265

Mybatis-plus 属于Mybatis的增强器,在其原基础上,只做了增强的作用,简化代码开发

和Mybatis的区别: 1、基础的语句可通过继承IService顶层接口进行实现

Mybatis-plus特性: 1、它不会对现有工程产生影响 2、启动即会自动注入基本 CURD,性能基本无损耗 3、支持 Lambda 形式调用 4、支持主键自动生成:支持多达 4 种主键策略 5、支持 ActiveRecord 形式调用,实体类(service)只需继承 IService 类即可进行强大的 CRUD 操作 6、内置分页插件:基于 MyBatis 物理分页 7、内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作

Mapper层集成 BaseMapper

注解: @TableName("gen_datasource_conf") 对象类上面 表示对应的表名 @TableId(value = "id", type = IdType.ASSIGN_ID) 主键注解:value:字段名 type:主键类型 IdType: AUTO:数据库ID自增 ASSIGN_ID:分配ID,主键类型为Number(Long和Integer)或String)使用接口IdentifierGenerator的方法nextId(默认实现类为DefaultIdentifierGenerator雪花算法) (默认) ASSIGN_UUID:分配UUID,主键类型为String(since 3.3.0),使用接口IdentifierGenerator的方法nextUUID(默认default方法) @TableField:数据库字段名 @Version:描述:乐观锁注解、

示例: wrappers:构造器内部方法

allEq({id:1,name:"老王",age:null})—>id = 1 and name = '老王' and age is null allEq({id:1,name:"老王",age:null}, false)—>id = 1 and name = '老王' allEq((k,v) -> k.indexOf("a") >= 0, {id:1,name:"老王",age:null})—>name = '老王' and age is null allEq((k,v) -> k.indexOf("a") >= 0, {id:1,name:"老王",age:null}, false)—>name = '老王' eq("name", "老王")—>name = '老王' ne("name", "老王")—>name '老王' gt("age", 18)—>age > 18 ge("age", 18)—>age >= 18 lt("age", 18)—>age < 18 le("age", 18)—>age age between 18 and 30 like("name", "王")—>name like '%王%' likeLeft("name", "王")—>name like '%王' isNull("name")—>name is null in("age",{1,2,3})—>age in (1,2,3) inSql("id", "select id from table where id < 3")—>id in (select id from table where id < 3) groupBy("id", "name")—>group by id,name orderByDesc("id", "name")—>order by id DESC,name DESC orderBy(true, true, "id", "name")—>order by id ASC,name ASC func(i -> if(true) {i.eq("id", 1)} else {i.ne("id", 1)}) eq("id",1).or().eq("name","老王")—>id = 1 or name = '老王' or(i -> i.eq("name", "李白").ne("status", "活着"))—>or (name = '李白' and status '活着') and(i -> i.eq("name", "李白").ne("status", "活着"))—>and (name = '李白' and status '活着') apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")—>date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'") exists("select id from table where age = 1")—>exists (select id from table where age = 1)

// 无条件分页查询 IPage pageMaps(IPage page); // 条件分页查询 IPage pageMaps(IPage page, Wrapper queryWrapper); // 查询总记录数 int count(); // 根据 Wrapper 条件,查询总记录数 int count(Wrapper queryWrapper); // 链式查询 普通 QueryChainWrapper query(); // 链式查询 lambda 式。注意:不支持 Kotlin LambdaQueryChainWrapper lambdaQuery();

// 示例: query().eq("column", value).one(); lambdaQuery().eq(Entity::getId, value).list(); // 链式更改 普通 UpdateChainWrapper update(); // 链式更改 lambda 式。注意:不支持 Kotlin LambdaUpdateChainWrapper lambdaUpdate();

// 示例: update().eq("column", value).remove(); lambdaUpdate().eq(Entity::getId, value).update(entity);

service.list(Wrappers.lambdaQuery().eq(SysOauthClientDetails::getClientId, clientId)));

配置项: 类名添加:@Configuration 类 实现 WebMvcConfigurer 重写 addArgumentResolvers方法实现SQL 过滤器避免SQL 注入



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3